﻿using MediatR;
using U.B.DoMain;
using U.B.ErrorCode;
using U.B.ReadApi.Command;
using U.B.Repistory;

namespace U.B.ReadApi.CommandHander
{
    public class GetLAIdCommandHander : IRequestHandler<GetLAIdCommand, ApiResult<LeaveApp>>
    {
        public IRepistory<LeaveApp> _leaveAppRepository;
public GetLAIdCommandHander(IRepistory<LeaveApp> leaveAppRepository)
        {
            _leaveAppRepository = leaveAppRepository;
        }
        public Task<ApiResult<LeaveApp>> Handle(GetLAIdCommand request, CancellationToken cancellationToken)
        {
            ApiResult<LeaveApp> result = new ApiResult<LeaveApp>();

            var la = _leaveAppRepository.GetAll().FirstOrDefault(x => x.LAId == request.LAId);
            if (la != null)
            {
                result.code = Renum.显示成功;
                result.Message = "查询成功";
                result.Data = la;
            }
            else
            {
                result.code = Renum.显示成功;
                result.Message = "查询失败";
            }
            return Task.FromResult(result);
        }
    }
}
